<?php
/**
 * Permission Service
 * User: zng
 * Date: 2019/11/4
 * Time: 14:34
 */
namespace app\admin\service\system;

use app\admin\model\system\System as SystemModels;
use think\db\Query;

Class System {

    /**
     * 首页列表
     * @param array $get 筛选条件
     * @author zx
     * @date 2020-03-24
     * @return \think\Paginator
     */
    public function indexPaginate( array $get=[] )
    {
        $map = [];
        if ( get($get, 'title') ) {
            $map[] = ['title', 'LIKE', $get['title'].'%'];
        }
        if ( get($get, 'key') ) {
            $map[] = ['title', 'LIKE', $get['title'].'%'];
        }
        $pageSize = get($get,'pageSize')>0?$get['pageSize']:20;
        return SystemModels::where($map)
            ->order('id', 'desc')
            ->paginate($pageSize);
    }

    /**
     * 新增\编辑信息
     * @param array $data 数据包
     * @author zx
     * @date 2020-03-17
     * @return boolean|integer
     */
    public function create(array $data)
    {
        $system = SystemModels::create($data, ['title','key','value']);
        return $system->isEmpty()?false:$system->id;
    }

    /**
     * 系统设置编辑
     * @param SystemModels $model
     * @param array $data
     * @return bool
     */
    public function save(SystemModels $model, array $data)
    {
        $model->title = $data['title'];
        $model->key = $data['key'];
        $model->value = $data['value'];
        return $model->save();
    }


}